// Copyright (C) 2010  Joan Puigcerver Perez, <joapuipe@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#include <Genres.hpp>

#include <cstring>

const uint32_t Genres::ID_ACTION  = 0x00000001;
const uint32_t Genres::ID_ADULT   = 0x00000002;
const uint32_t Genres::ID_ADVENT  = 0x00000004;
const uint32_t Genres::ID_ANIMAT  = 0x00000008;
const uint32_t Genres::ID_BIOGRA  = 0x00000010;
const uint32_t Genres::ID_COMEDY  = 0x00000020;
const uint32_t Genres::ID_CRIME   = 0x00000040;
const uint32_t Genres::ID_DOCUMEN = 0x00000080;
const uint32_t Genres::ID_DRAMA   = 0x00000100;
const uint32_t Genres::ID_FAMILY  = 0x00000200;
const uint32_t Genres::ID_FANTASY = 0x00000400;
const uint32_t Genres::ID_FNOIR   = 0x00000800;
const uint32_t Genres::ID_GSHOW   = 0x00001000;
const uint32_t Genres::ID_HISTORY = 0x00002000;
const uint32_t Genres::ID_HORROR  = 0x00004000;
const uint32_t Genres::ID_MUSIC   = 0x00008000;
const uint32_t Genres::ID_MUSICAL = 0x00010000;
const uint32_t Genres::ID_MYSTERY = 0x00020000;
const uint32_t Genres::ID_NEWS    = 0x00040000;
const uint32_t Genres::ID_REALTV  = 0x00080000;
const uint32_t Genres::ID_ROMANCE = 0x00100000;
const uint32_t Genres::ID_SCIFI   = 0x00200000;
const uint32_t Genres::ID_SHORT   = 0x00400000;
const uint32_t Genres::ID_SPORT   = 0x00800000;
const uint32_t Genres::ID_TSHOW   = 0x01000000;
const uint32_t Genres::ID_THRILL  = 0x02000000;
const uint32_t Genres::ID_WAR     = 0x04000000;
const uint32_t Genres::ID_WESTERN = 0x08000000;
const uint32_t Genres::ID_UNKNOWN = 0x80000000;
const uint32_t Genres::ID_ALL     = 0xFFFFFFFF;

const char * Genres::TAG_ACTION   = "Action";
const char * Genres::TAG_ADULT    = "Adult";
const char * Genres::TAG_ADVENT   = "Adventure";
const char * Genres::TAG_ANIMAT   = "Animation";
const char * Genres::TAG_BIOGRA   = "Biography";
const char * Genres::TAG_COMEDY   = "Comedy";
const char * Genres::TAG_CRIME    = "Crime";
const char * Genres::TAG_DOCUMEN  = "Documentary";
const char * Genres::TAG_DRAMA    = "Drama";
const char * Genres::TAG_FAMILY   = "Family";
const char * Genres::TAG_FANTASY  = "Fantasy";
const char * Genres::TAG_FNOIR    = "Film-Noir";
const char * Genres::TAG_GSHOW    = "Game-Show";
const char * Genres::TAG_HISTORY  = "History";
const char * Genres::TAG_HORROR   = "Horror";
const char * Genres::TAG_MUSIC    = "Music";
const char * Genres::TAG_MUSICAL  = "Musical";
const char * Genres::TAG_MYSTERY  = "Mystery";
const char * Genres::TAG_NEWS     = "News";
const char * Genres::TAG_REALTV   = "Reality-TV";
const char * Genres::TAG_ROMANCE  = "Romance";
const char * Genres::TAG_SCIFI    = "Sci-Fi";
const char * Genres::TAG_SHORT    = "Short";
const char * Genres::TAG_SPORT    = "Sport";
const char * Genres::TAG_TSHOW    = "Talk-Show";
const char * Genres::TAG_THRILL   = "Thriller";
const char * Genres::TAG_WAR      = "War";
const char * Genres::TAG_WESTERN  = "Western";
const char * Genres::TAG_UNKNOWN  = "Unknown";
const char * Genres::TAG_ALL      = "All";

Genres::Genres() : _genres(ID_UNKNOWN)
{
}

Genres::Genres(const uint32_t genres) : _genres(genres)
{
}

Genres::Genres(const char * genre)
{
  if ( !strcasecmp(genre, TAG_ACTION) )
    _genres = ID_ACTION;
  else if ( !strcasecmp(genre, TAG_ADULT) )
    _genres = ID_ADULT;
  else if ( !strcasecmp(genre, TAG_ADVENT) )
    _genres = ID_ADVENT;
  else if ( !strcasecmp(genre, TAG_ANIMAT) )
    _genres = ID_ANIMAT;
  else if ( !strcasecmp(genre, TAG_BIOGRA) )
    _genres = ID_BIOGRA;
  else if ( !strcasecmp(genre, TAG_COMEDY) )
    _genres = ID_COMEDY;
  else if ( !strcasecmp(genre, TAG_CRIME) )
    _genres = ID_CRIME;
  else if ( !strcasecmp(genre, TAG_DOCUMEN) )
    _genres = ID_DOCUMEN;
  else if ( !strcasecmp(genre, TAG_DRAMA) )
    _genres = ID_DRAMA;
  else if ( !strcasecmp(genre, TAG_FAMILY) )
    _genres = ID_FAMILY;
  else if ( !strcasecmp(genre, TAG_FANTASY) )
    _genres = ID_FANTASY;
  else if ( !strcasecmp(genre, TAG_FNOIR) )
    _genres = ID_FNOIR;
  else if ( !strcasecmp(genre, TAG_GSHOW) )
    _genres = ID_GSHOW;
  else if ( !strcasecmp(genre, TAG_HISTORY) )
    _genres = ID_HISTORY;
  else if ( !strcasecmp(genre, TAG_HORROR) )
    _genres = ID_HORROR;
  else if ( !strcasecmp(genre, TAG_MUSIC) )
    _genres = ID_MUSIC;
  else if ( !strcasecmp(genre, TAG_MUSICAL) )
    _genres = ID_MUSICAL;
  else if ( !strcasecmp(genre, TAG_MYSTERY) )
    _genres = ID_MYSTERY;
  else if ( !strcasecmp(genre, TAG_NEWS) )
    _genres = ID_NEWS;
  else if ( !strcasecmp(genre, TAG_REALTV) )
    _genres = ID_REALTV;
  else if ( !strcasecmp(genre, TAG_ROMANCE) )
    _genres = ID_ROMANCE;
  else if ( !strcasecmp(genre, TAG_SCIFI) )
    _genres = ID_SCIFI;
  else if ( !strcasecmp(genre, TAG_SHORT) )
    _genres = ID_SHORT;
  else if ( !strcasecmp(genre, TAG_SPORT) )
    _genres = ID_SPORT;
  else if ( !strcasecmp(genre, TAG_TSHOW) )
    _genres = ID_TSHOW;
  else if ( !strcasecmp(genre, TAG_THRILL) )
    _genres = ID_THRILL;
  else if ( !strcasecmp(genre, TAG_WAR) )
    _genres = ID_WAR;
  else if ( !strcasecmp(genre, TAG_WESTERN) )
    _genres = ID_WESTERN;
  else if ( !strcasecmp(genre, TAG_ALL) )
    _genres = ID_ALL;
  else
    _genres = ID_UNKNOWN;
}
  
Genres& Genres::operator = (const uint32_t genres)
{
  _genres = genres;
  return *this;
}
 
bool Genres::operator == (const Genres& genres) const
{
  return ( genres._genres == genres );
}

bool Genres::operator == (const uint32_t genres) const
{
  return ( genres == _genres );
}

bool Genres::operator != (const Genres& genres) const
{
  return ( genres._genres != _genres );
}
bool Genres::operator != (const uint32_t genres) const
{
  return ( genres != _genres );
}

Genres::operator uint32_t () const
{
  return _genres;
}

Genres::operator const char * () const
{
  switch(_genres) {
  case ID_ACTION:
    return TAG_ACTION;
  case ID_ADULT:
    return TAG_ADULT;
  case ID_ADVENT:
    return TAG_ADVENT;
  case ID_ANIMAT:
    return TAG_ANIMAT;
  case ID_BIOGRA:
    return TAG_BIOGRA;
  case ID_COMEDY:
    return TAG_COMEDY;
  case ID_CRIME:
    return TAG_CRIME;
  case ID_DOCUMEN:
    return TAG_DOCUMEN;
  case ID_DRAMA:
    return TAG_DRAMA;
  case ID_FAMILY:
    return TAG_FAMILY;
  case ID_FANTASY:
    return TAG_FANTASY;
  case ID_FNOIR:
    return TAG_FNOIR;
  case ID_GSHOW:
    return TAG_GSHOW;
  case ID_HISTORY:
    return TAG_HISTORY;
  case ID_HORROR:
    return TAG_HORROR;
  case ID_MUSIC:
    return TAG_MUSIC;
  case ID_MUSICAL:
    return TAG_MUSICAL;
  case ID_MYSTERY:
    return TAG_MYSTERY;
  case ID_NEWS:
    return TAG_NEWS;
  case ID_REALTV:
    return TAG_REALTV;
  case ID_ROMANCE:
    return TAG_ROMANCE;
  case ID_SCIFI:
    return TAG_SCIFI;
  case ID_SHORT:
    return TAG_SHORT;
  case ID_SPORT:
    return TAG_SPORT;
  case ID_TSHOW:
    return TAG_TSHOW;
  case ID_THRILL:
    return TAG_THRILL;
  case ID_WAR:
    return TAG_WAR;
  case ID_WESTERN:
    return TAG_WESTERN;
  case ID_ALL:
    return TAG_ALL;
  default: 
    return TAG_UNKNOWN;
  }
}

bool Genres::mask(const Genres& genres_a, const Genres& genres_b)
{
  return ( ( genres_a._genres & genres_b._genres ) != 0x00000000 );
}
